﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Collections;
using System.IO;
using System.Drawing;
using System.Text;

public partial class goodsinfor1 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["name"] == null)
        {
            Response.Redirect("~/error.aspx?");
        }
        string JudgePower = Session["power"].ToString();
        if (JudgePower != "超级管理员" && JudgePower != "仓库管理员" && JudgePower != "销售" && JudgePower != "查询用户" && JudgePower != "工程师" && JudgePower != "主管")
        {

            Response.Redirect("~/PowerError.aspx?");
        }
        if (!IsPostBack)
        {
            this.bind1();
        }

    }

    protected void Button3_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/daochu.aspx?");
    }

    public SqlConnection GetConnection()
    {
        string myStr = ConfigurationManager.AppSettings["ConnectionString"].ToString();
        SqlConnection myConn = new SqlConnection(myStr);
        return myConn;
    }

    protected void bind()
    {
        SqlConnection myConn = GetConnection();
        myConn.Open();
        string sqlStr = "select GID as 货品编号,GTYPEName as 类别,GCHName as 名称,GXinhao as 型号,GBrand as 品牌,GUnit as 单位,GProvider1 as 主供应商,GProvider2  as 次供应商,GDescribe as 备注 from [Goods] where GTYPEName ='" + DropDownList1.SelectedValue.ToString() + "'";
        SqlDataAdapter myDa = new SqlDataAdapter(sqlStr, myConn);
        DataSet myDs = new DataSet();
        myDa.Fill(myDs);
        GridView1.DataSource = myDs;
        GridView1.DataKeyNames = new string[] { "货品编号" };
        GridView1.DataBind();
        myDa.Dispose();
        myDs.Dispose();

        string sql1 = "select CName from Categories";
        SqlDataAdapter sqlDa = new SqlDataAdapter(sql1, myConn);
        DataSet sqlDs = new DataSet();
        sqlDa.Fill(sqlDs);
        DropDownList1.DataSource = sqlDs;
        DropDownList1.DataTextField = "CName";
        DropDownList1.DataBind();
        this.DropDownList1.Items.Insert(0, new ListItem("------------", "------------"));
        this.DropDownList1.Items.Insert(1, new ListItem("查看全部", "查看全部"));
        sqlDa.Dispose();
        sqlDs.Dispose();

        myConn.Close();
    }

    protected void bind1()
    {
        SqlConnection myConn = GetConnection();
        myConn.Open();
        string sqlStr = "select GID as 货品编号,GTYPEName as 类别,GCHName as 名称,GXinhao as 型号,GBrand as 品牌,GUnit as 单位,GProvider1 as 主供应商,GProvider2  as 次供应商,GDescribe as 备注 from [Goods]";
        SqlDataAdapter myDa = new SqlDataAdapter(sqlStr, myConn);
        DataSet myDs = new DataSet();
        myDa.Fill(myDs);
        GridView1.DataSource = myDs;
        GridView1.DataKeyNames = new string[] { "货品编号" };
        GridView1.DataBind();
        myDa.Dispose();
        myDs.Dispose();

        string sql1 = "select CName from Categories";
        SqlDataAdapter sqlDa = new SqlDataAdapter(sql1, myConn);
        DataSet sqlDs = new DataSet();
        sqlDa.Fill(sqlDs);
        DropDownList1.DataSource = sqlDs;
        DropDownList1.DataTextField = "CName";
        DropDownList1.DataBind();
        this.DropDownList1.Items.Insert(0, new ListItem("------------", "------------"));
        this.DropDownList1.Items.Insert(1, new ListItem("查看全部", "查看全部"));
        sqlDa.Dispose();
        sqlDs.Dispose();

        myConn.Close();
    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (DropDownList1.SelectedValue.ToString() == "查看全部")
        {
            this.bind1();
            //Response.Redirect("~/goodsinfor.aspx?");
        }
        else
        {
            this.bind();
            //Response.Redirect("~/goodsinfor.aspx?");
        }
    }
}